package io;

import java.io.*;

/**
 * @Author Justin Parker
 * @Date 2024/7/16 0016 16:52
 * @Version 1.0
 */
/*
 * 将messgae.txt文件中的内容进行反序列化
 */
public class ObjectInputStreamDemo02 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //1.创建流对象
        ObjectInputStream ois =
                new ObjectInputStream(
                    new BufferedInputStream(
                            new FileInputStream("msg.txt"))); //FileNotFoundException
        //2.读取对象(反序列化-先读出来的是字节，然后将字节转换对象)
        Message msg1 =(Message)ois.readObject();
        Message msg2 =(Message)ois.readObject();// IOException, ClassNotFoundException
        //4.使用读取到的对象
        System.out.println(msg1);
        System.out.println(msg2);
        System.out.println("反序列化ok");
        //3.关闭资源
        ois.close();
    }
}
